﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Platform.Model
{
	/// <summary>
	/// Lop luu tru du lieu thuong truc trong phien lam viec
	/// </summary>
	public class WorkContext
	{
		private static WorkContext _instance = null;

		/// <summary>
		/// Lay doi tuong quan ly du lieu hien hanh
		/// </summary>
		public static WorkContext Current
		{
			get { return _instance ?? (_instance = new WorkContext()); }
		}

		/// <summary>
		/// Doi tuong quan ly danh sach mat hang
		/// </summary>
		public ProductList Articles { get; set; }

		/// <summary>
		/// Doi tuong quan ly danh sach nha cung cap
		/// </summary>
		public ProviderList Suppliers { get; set; }

		/// <summary>
		/// Doi tuong quan ly danh sach cac kho cua sieu thi
		/// </summary>
		public Warehouse Storages { get; set; }

		/// <summary>
		/// Khoi tao doi tuong quan ly du lieu cua phien lam viec
		/// </summary>
		private WorkContext()
		{
			Articles = new ProductList();
			Suppliers = new ProviderList();
			Storages = new Warehouse();
		}

		/// <summary>
		/// Tai va cap nhat lai du lieu da bi thay doi
		/// ke tu thoi diem cho truoc
		/// </summary>
		public void Reload(DateTime? lastRefresh = null)
		{
			Articles.Refresh(lastRefresh);
			Suppliers.Refresh(lastRefresh);
			Storages.Refresh(lastRefresh);
		}
	}
}
